package com.oracle.sbdb.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oracle.sbdb.bo.EngineerBo;
import com.oracle.sbdb.model.Engineer;
import com.oracle.sbdb.servlet.model.EngineerInformation;
import com.oracle.sbdb.util.JSONUtility;

/**
 * Servlet implementation class CheckPassword
 */
@WebServlet("/checkPassword")
public class CheckPassword extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public CheckPassword() {
		super();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		System.out.println(username + "  "+password);
		EngineerInformation engineerInformation = null;

		if (username != null && password != null) {
			engineerInformation = EngineerBo.INSTANCE.checkPassword(username,
					password);
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("Status", engineerInformation == null ? "Fail" : "Success");
		map.put("Result", engineerInformation);

		PrintWriter out = response.getWriter();
		out.write(JSONUtility.bean2Json(map));
		out.flush();
		out.close();
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
	}

}
